namespace CIS.Resource
{
    using CISLib;
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class ResourceSearchPage : Page
    {
        protected DropDownList HotelStarDdl;
        protected Image iSearch;
        protected Label lbCity;
        protected Label lbHotelStar;
        protected Label lbProcince;
        protected Label lbResourceType;
        protected Label lbSearchKey;
        protected UserPrincipal Principal = null;
        protected DropDownList ResourceCityDdl;
        protected TextBox ResourceKeyTxb;
        protected DropDownList ResourceProvinceDdl;
        protected DropDownList ResourceTypeDdl;
        protected Button searchBtn;

        private void InitializeComponent()
        {
            this.ResourceTypeDdl.SelectedIndexChanged += new EventHandler(this.ResourceTypeDdl_SelectedIndexChanged);
            this.ResourceProvinceDdl.SelectedIndexChanged += new EventHandler(this.ResourceProvinceDdl_SelectedIndexChanged);
            this.searchBtn.Click += new EventHandler(this.searchBtn_Click);
            base.Load += new EventHandler(this.Page_Load);
        }

        private void InitPage()
        {
            this.SetFromImage();
            this.SetFrom();
            this.ResourceProvinceDdl.DataSource = ManageProvince.GetProvinceNoAll();
            this.ResourceProvinceDdl.DataTextField = "RegionName";
            this.ResourceProvinceDdl.DataValueField = "RegionId";
            this.ResourceProvinceDdl.DataBind();
            Guid uid = new Guid();
            this.ResourceProvinceDdl.Items.Insert(0, new ListItem("All", uid.ToString()));
            this.ResourceCityDdl.DataSource = ManageCity.GetCityViaProvinceId(new Guid(this.ResourceProvinceDdl.SelectedItem.Value));
            this.ResourceCityDdl.DataTextField = "regionName";
            this.ResourceCityDdl.DataValueField = "regionId";
            this.ResourceCityDdl.DataBind();
            this.HotelStarDdl.Items.Clear();
            string stri = "";
            this.HotelStarDdl.Items.Add(new ListItem("", "0"));
            for (int i = 1; i <= 5; i++)
            {
                ListItem item = new ListItem();
                item.Value = i.ToString();
                stri = stri + "*";
                item.Text = stri;
                this.HotelStarDdl.Items.Add(item);
            }
            ListItem tmpItem1 = new ListItem();
            tmpItem1.Text = "协议酒店信息";
            tmpItem1.Value = "1";
            this.ResourceTypeDdl.Items.Add(tmpItem1);
            ListItem tmpItem2 = new ListItem();
            tmpItem2.Text = "推存餐饮信息";
            tmpItem2.Value = "2";
            this.ResourceTypeDdl.Items.Add(tmpItem2);
            ListItem tmpItem3 = new ListItem();
            tmpItem3.Text = "休闲娱乐";
            tmpItem3.Value = "3";
            this.ResourceTypeDdl.Items.Add(tmpItem3);
            ListItem tmpItem4 = new ListItem();
            tmpItem4.Text = "服务代理";
            tmpItem4.Value = "4";
            this.ResourceTypeDdl.Items.Add(tmpItem4);
            ListItem tmpItem5 = new ListItem();
            tmpItem5.Text = "医院";
            tmpItem5.Value = "5";
            this.ResourceTypeDdl.Items.Add(tmpItem5);
            ListItem tmpItem6 = new ListItem();
            tmpItem6.Text = "展览活动";
            tmpItem6.Value = "6";
            this.ResourceTypeDdl.Items.Add(tmpItem6);
            ListItem tmpItem7 = new ListItem();
            tmpItem7.Text = "特色节日";
            tmpItem7.Value = "7";
            this.ResourceTypeDdl.Items.Add(tmpItem7);
            ListItem tmpItem8 = new ListItem();
            tmpItem8.Text = "常用电话";
            tmpItem8.Value = "8";
            this.ResourceTypeDdl.Items.Add(tmpItem8);
            ListItem tmpItem9 = new ListItem();
            tmpItem9.Text = "分公司通信录";
            tmpItem9.Value = "9";
            this.ResourceTypeDdl.Items.Add(tmpItem9);
            ListItem tmpItem10 = new ListItem();
            tmpItem10.Text = "其他信息";
            tmpItem10.Value = "10";
            this.ResourceTypeDdl.Items.Add(tmpItem10);
            ListItem tmpItem11 = new ListItem();
            tmpItem11.Text = "销售小技巧";
            tmpItem11.Value = "11";
            this.ResourceTypeDdl.Items.Add(tmpItem11);
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
            this.Principal = this.Context.User as UserPrincipal;
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.InitPage();
            }
        }

        private void ResourceProvinceDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.ResourceCityDdl.DataSource = ManageCity.GetCityViaProvinceId(new Guid(this.ResourceProvinceDdl.SelectedItem.Value));
            this.ResourceCityDdl.DataTextField = "regionName";
            this.ResourceCityDdl.DataValueField = "regionId";
            this.ResourceCityDdl.DataBind();
            this.ResourceCityDdl.Items.Insert(0, new ListItem("All", "00000000-0000-0000-0000-000000000001"));
        }

        private void ResourceTypeDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.ResourceTypeDdl.SelectedValue == "9")
            {
                this.ResourceProvinceDdl.Visible = true;
                this.lbProcince.Visible = true;
                this.ResourceCityDdl.Visible = false;
                this.lbCity.Visible = false;
            }
            else if (this.ResourceTypeDdl.SelectedValue == "10")
            {
                this.ResourceCityDdl.Visible = false;
                this.lbCity.Visible = false;
                this.ResourceProvinceDdl.Visible = false;
                this.lbProcince.Visible = false;
            }
            else if (this.ResourceTypeDdl.SelectedValue == "11")
            {
                this.ResourceCityDdl.Visible = false;
                this.lbCity.Visible = false;
                this.ResourceProvinceDdl.Visible = false;
                this.lbProcince.Visible = false;
            }
            else if (this.ResourceTypeDdl.SelectedValue == "1")
            {
                this.lbHotelStar.Visible = true;
                this.HotelStarDdl.Visible = true;
            }
            else
            {
                this.ResourceCityDdl.Visible = true;
                this.lbCity.Visible = true;
                this.ResourceProvinceDdl.Visible = true;
                this.lbProcince.Visible = true;
                this.lbHotelStar.Visible = false;
                this.HotelStarDdl.Visible = false;
            }
        }

        private void searchBtn_Click(object sender, EventArgs e)
        {
            Guid cityId = new Guid("00000000-0000-0000-0000-000000000001");
            if (this.ResourceCityDdl.Items.Count != 0)
            {
                cityId = new Guid(this.ResourceCityDdl.SelectedItem.Value);
            }
            switch (this.ResourceTypeDdl.SelectedItem.Value)
            {
                case "1":
                    this.Page.Session.Add("ProvinceId", this.ResourceProvinceDdl.SelectedValue);
                    this.Page.Session.Add("CityId", cityId);
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    this.Page.Session.Add("Star", this.HotelStarDdl.SelectedValue);
                    base.Response.Redirect("ResourceHotelPage.aspx?IsSearch=True", true);
                    break;

                case "2":
                    this.Page.Session.Add("ProvinceId", this.ResourceProvinceDdl.SelectedValue);
                    this.Page.Session.Add("CityId", cityId);
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceRestaurantPage.aspx?IsSearch=True", true);
                    break;

                case "3":
                    this.Page.Session.Add("ProvinceId", this.ResourceProvinceDdl.SelectedValue);
                    this.Page.Session.Add("CityId", cityId);
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceEntertainmentPage.aspx?IsSearch=True", true);
                    break;

                case "4":
                    this.Page.Session.Add("ProvinceId", this.ResourceProvinceDdl.SelectedValue);
                    this.Page.Session.Add("CityId", cityId);
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceAgenciesPage.aspx?IsSearch=True", true);
                    break;

                case "5":
                    this.Page.Session.Add("ProvinceId", this.ResourceProvinceDdl.SelectedValue);
                    this.Page.Session.Add("CityId", cityId);
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceHospitalPage.aspx?IsSearch=True", true);
                    break;

                case "6":
                    this.Page.Session.Add("ProvinceId", this.ResourceProvinceDdl.SelectedValue);
                    this.Page.Session.Add("CityId", cityId);
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceEventsPage.aspx?IsSearch=True", true);
                    break;

                case "7":
                    this.Page.Session.Add("ProvinceId", this.ResourceProvinceDdl.SelectedValue);
                    this.Page.Session.Add("CityId", cityId);
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceHolidayPage.aspx?IsSearch=True", true);
                    break;

                case "8":
                    this.Page.Session.Add("ProvinceId", this.ResourceProvinceDdl.SelectedValue);
                    this.Page.Session.Add("CityId", cityId);
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceTelephonePage.aspx?IsSearch=True", true);
                    break;

                case "9":
                    this.Page.Session.Add("ProvinceId", this.ResourceProvinceDdl.SelectedValue);
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceDirectoryPage.aspx?IsSearch=True", true);
                    break;

                case "10":
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceOtherPage.aspx?IsSearch=True", true);
                    break;

                case "11":
                    this.Page.Session.Add("Key", this.ResourceKeyTxb.Text.Trim());
                    base.Response.Redirect("ResourceTipPage.aspx?IsSearch=True", true);
                    break;
            }
        }

        private void SetFrom()
        {
            string language = this.Session["language"].ToString();
            string path = base.Server.MapPath("~/LanguageConfig.xml");
            this.lbResourceType.Text = ManageSystemConfig.GetSystemSetLanguage("ResourceSearchPage", "lbResourceType", language, path);
            if (this.Principal.OwnArea[0].AreaId.ToString() == "a7f26634-10a9-4cb1-aa2c-8c91a8dfdd66")
            {
                this.lbProcince.Text = ManageSystemConfig.GetSystemSetLanguage("ResourceSearchPage", "lbProcinceOverSea", language, path);
                this.lbCity.Text = ManageSystemConfig.GetSystemSetLanguage("ResourceSearchPage", "lbCityOverSea", language, path);
            }
            else
            {
                this.lbProcince.Text = ManageSystemConfig.GetSystemSetLanguage("ResourceSearchPage", "lbProcince", language, path);
                this.lbCity.Text = ManageSystemConfig.GetSystemSetLanguage("ResourceSearchPage", "lbCity", language, path);
            }
            this.lbSearchKey.Text = ManageSystemConfig.GetSystemSetLanguage("ResourceSearchPage", "lbSearchKey", language, path);
            this.searchBtn.Text = ManageSystemConfig.GetSystemSetLanguage("ResourceSearchPage", "searchBtn", language, path);
            this.lbHotelStar.Text = ManageSystemConfig.GetSystemSetLanguage("ResourceSearchPage", "lbHotelStar", language, path);
        }

        private void SetFromImage()
        {
            switch (this.Session["language"].ToString())
            {
                case "cn":
                    this.iSearch.ImageUrl = "../images/Title_Search.jpg";
                    break;

                case "en":
                    this.iSearch.ImageUrl = "../images/Title_SearchEn.jpg";
                    break;
            }
        }
    }
}

